<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_pig_file".
 *
 * @property string $id
 * @property string $name
 * @property string $no
 * @property string $father
 * @property string $mathor
 * @property integer $variety
 */
class BusinessPigFile extends \yii\db\ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '仔猪档案',      //用于修改了什么的显示
        'mainfield' => 'name',      //主要的显示标题的字段
        'picturefield' => ['matherphoto','fatherphoto'],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_pig_file';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'no', 'variety','constract_id'], 'required'],
            ['no','unique'],
            [['variety','constract_id'], 'integer'],
            [['name', 'no', 'father', 'mathor'], 'string', 'max' => 255],
            [['matherphoto','fatherphoto'], 'image', 'extensions' => 'jpg, jpeg, gif, png', 'on' => ['insert', 'update']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '档案名称',
            'no' => '档案编号',
            'father' => '父本编号',
            'mathor' => '母本编号',
            'variety' => '品种',
            'matherphoto' => '母本照片',
            'fatherphoto' => '父本照片',
            'constract_id' => '合同',
            'pigs' => '包含的猪仔'
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取合同
     */
    public function getConstract()
    {
        return $this->hasOne(BusinessContract::className(),['id'=>'constract_id']);

    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取品种
     */
    public function getVarietyname()
    {
        return $this->hasOne(BusinessVariety::className(),['id'=>'variety']);

    }


    public function getPigs()
    {
        return $this->hasMany(BusinessPig::className(),['fileid'=>'id']);
    }


}
